/**
 * entry.js - 微前端入口文件
 * 这个文件会被部署到CDN，并被qiankun直接加载
 */
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
  (global = global || self, factory(global['educoder-preview'] = {}));
}(this, (function (exports) { 'use strict';

  // 定义生命周期函数
  function bootstrap() {
    console.log('[educoder-preview] bootstrap from entry.js');
    // 如果已经加载了主应用，调用主应用的bootstrap函数
    if (window.bootstrap) {
      return window.bootstrap();
    }
    return Promise.resolve();
  }

  function mount(props) {
    console.log('[educoder-preview] mount from entry.js', props);
    // 如果已经加载了主应用，调用主应用的mount函数
    if (window.mount) {
      return window.mount(props);
    }
    // 如果没有加载主应用，加载主应用
    return loadApp().then(() => {
      if (window.mount) {
        return window.mount(props);
      }
      return Promise.resolve();
    });
  }

  function unmount() {
    console.log('[educoder-preview] unmount from entry.js');
    // 如果已经加载了主应用，调用主应用的unmount函数
    if (window.unmount) {
      return window.unmount();
    }
    return Promise.resolve();
  }

  // 加载主应用
  function loadApp() {
    return new Promise((resolve, reject) => {
      // 加载主应用的JS文件
      const script = document.createElement('script');
      script.src = './index.js';
      script.onload = resolve;
      script.onerror = reject;
      document.head.appendChild(script);
    });
  }

  // 导出生命周期函数
  exports.bootstrap = bootstrap;
  exports.mount = mount;
  exports.unmount = unmount;

  Object.defineProperty(exports, '__esModule', { value: true });

}))); 